//酒店选择
$("#picker").picker({
  toolbarTemplate: '<header class="bar bar-nav">\
  <button class="button button-link pull-left"></button>\
  <button class="button button-link pull-right close-picker">确定</button>\
  <h1 class="title">请选择要入住的酒店</h1>\
  </header>',
  cols: [
    {
      textAlign: 'center',
      values: ['龙里店', '绥阳店', '威宁店', '思南店', '开阳店', '石阡店','临江店', '平塘店', '贞丰店', '三穗店', '晴隆店']
    }
  ]
});


//支付方式
$("#pay").picker({
  toolbarTemplate: '<header class="bar bar-nav">\
  <button class="button button-link pull-left"></button>\
  <button class="button button-link pull-right close-picker">确定</button>\
  <h1 class="title">请选择付款方式</h1>\
  </header>',
  cols: [
    {
      textAlign: 'center',
      values: ['微信', '支付宝', '银行卡']
    }
  ]
});

//房间类型

$("#roomtype").picker({
  toolbarTemplate: '<header class="bar bar-nav">\
  <button class="button button-link pull-left"></button>\
  <button class="button button-link pull-right close-picker">确定</button>\
  <h1 class="title">请选择房间类型</h1>\
  </header>',
  cols: [
    {
      textAlign: 'center',
      values: ['标准单人间', '标准双人间', '标准三人间', '电脑单人房', '电脑双人房', '麻将娱乐房']
    }
  ]
});

//身份证

if($('#idcard').eq(0)){
  $('#idcard').change(function(){
    var isIDCard=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
    var value = $(this).val();
    var result = isIDCard.test(value);
    if(!result){
      alert('请输入正确的身份证号码');
    }
  })
}

/*多选框*/
checked("#sheshiok",'.sheshi','#sheshifuwu');
checked('#cuxiaook','.cuxiao','#jiudiancuxiao');
function checked(btn,className,text) {
  $(btn).click(function() {
    var str = "";
    $(className).each(function(index) {
      if($(this).is(":checked")){
        str+=$(this).val()+",";
      }
    });
    str=str.substring(0,str.length-1);
    $(text).val(str);
  });
}




//底部弹出层控件
$(document).on('click','.create-actions', function () {
  var buttons1 = [
    {
      text: '请选择',
      label: true
    },
    {
      text: '客服1',
      bold: true,
      onClick: function() {
    	  window.location.href = 'tel://' + 18084488688;  
       // $.alert("18072750743");
        sub.click(); 
      }
    },
    {
      text: '客服2',
      onClick: function() {
    	  window.location.href = 'tel://' + 18084488688;  
      }
    },
    {
      text: '酒店加盟',
      onClick: function() {
    	  window.location.href = 'tel://' + 18084488688;  
      }
    }
  ];
  var buttons2 = [
    {
      text: '取消',
      bg: 'danger'
    }
  ];
  var groups = [buttons1, buttons2];
  $.actions(groups);
});

//滚动顶部控件
$(".reachbtn").bind("touchstart",function(event) {
	$(".native-scroll").scrollTo({toT:0});
})
$.fn.scrollTo =function(options){
  var defaults = {
      toT : 0,    //滚动目标位置
      durTime : 300,  //过渡动画时间
      delay : 30,     //定时器时间
      callback:null   //回调函数
  };
  var opts = $.extend(defaults,options),
      timer = null,
      _this = this,
      curTop = _this.scrollTop(),//滚动条当前的位置
      subTop = opts.toT - curTop,    //滚动条目标位置和当前位置的差值
      index = 0,
      dur = Math.round(opts.durTime / opts.delay),
      smoothScroll = function(t){
          index++;
          var per = Math.round(subTop/dur);
          if(index >= dur){
              _this.scrollTop(t);
              window.clearInterval(timer);
              if(opts.callback && typeof opts.callback == 'function'){
                  opts.callback();
              }
              return;
          }else{
              _this.scrollTop(curTop + index*per);
          }
      };
  timer = window.setInterval(function(){
      smoothScroll(opts.toT);
  }, opts.delay);
  return _this;
};
//应用初始化
$.init();

//预订页面选项卡
if(document.getElementsByClassName('qt-control-line-group').length){
  ydymxxk();
}  
function ydymxxk(){
  var ulTab = document.getElementsByClassName('qt-control-line-group')[0];
  var liTabs = ulTab.getElementsByTagName('li');
  var tabbuttom = document.getElementById('tab-buttom');
  liTabs[0].onclick=function(){
    liTabs[1].className="";
    //this.className="qt-br-x1 active";
    //document.getElementById('normal-room').className="";
    //document.getElementById('hour-room').className="qt-hide";
    tabbuttom.style.transform = "translate3d(2rem, 0px, 0px)";
  }
  liTabs[1].onclick=function(){
    //liTabs[0].className="qt-br-x1";
    //this.className="active";
    //document.getElementById('normal-room').className="qt-hide";
    //document.getElementById('hour-room').className="";
    tabbuttom.style.transform = "translate3d(11rem, 0px, 0px)";
  }
}


//城市选择
if($('#city').length){
  $('#city').cityPicker(); 
  $('#city1').cityPicker(); 
}


//酒店介绍选项卡
if(document.getElementsByClassName('smalllist').length){
  jdjsxxk();
}
function jdjsxxk(){
  var smalllist = document.getElementsByClassName('smalllist');
  var tabpanel = document.getElementsByClassName('tabpanel');
  var listcontent = document.getElementById('listcontent');
  listcontent.style.width = document.documentElement.clientWidth*(smalllist.length+1)+"px";
  for(var i=0;i<smalllist.length;i++){
    smalllist[i].index=i;
    smalllist[i].addEventListener('touchstart',function(event){
      
      var clientWidth = document.documentElement.clientWidth;
      
      listcontent.style.left = -clientWidth*this.index+"px";
      console.log(-clientWidth*this.index+"px");
    })
  }
}

